package com.yang.jpa.dao;

import com.yang.jpa.model.Member;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MemberDao extends JpaRepository<Member, Integer>, JpaSpecificationExecutor<Member> {

    List<Member> findByName(String name);

    @Query(value = "select m from members m where m.name = ?1")
    List<Member> findMemberListByName(String name);

    @Query(value = "select * from members where name = ?1 and created_at like ?2", nativeQuery = true)
    List<Member> findMemberListByNameCreatedAt(String name, String createdAt);

    @Query(value = "select * from members where name like :name and created_at like :created_at", nativeQuery = true)
    List<Member> findMemberListByNameCreatedAtParam(@Param("name") String name, @Param("created_at") String createdAt);

    @Modifying
    @Query(value = "update members set name = ?1 where id = ?2")
    public void updateMemberById(String name, int id);
}
